$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加订单', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'account',
                title: '用户账号',
                unresize: true,
                align: 'center'
            }, {
                field: 'status',
                title: '订单状态',
                unresize: true,
                align: 'center',
                templet: function(data){
                    switch(data.status){
                        case 0:return '未支付';break;
                        case 1:return '已支付';break;
                        case 2:return '待收货';break;
                        case 3:return '已收货';break;
                        case 4:return '已评价';break;
                        case 5:return '已取消';break;
                    }
                }
            }, {
                field: 'add_time',
                title: '下单时间',
                unresize: true,
                align: 'center'
            }, {
                field: 'num',
                title: '商品数量',
                unresize: true,
                align: 'center'
            }, {
                field: 'all_money',
                title: '订单总价',
                unresize: true,
                align: 'center'
            }, {
                field: 'number',
                title: '订单编号',
                unresize: true,
                align: 'center'
            }, {
                field: 'address',
                title: '收货地址',
                unresize: true,
                align: 'center'
            }, {
                field: 'pay_time',
                title: '支付时间',
                unresize: true,
                align: 'center'
            }, {
                field: 'introduce',
                title: '备注',
                unresize: true,
                align: 'center'
            }, {
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑订单', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该订单吗?', 'admin_order', obj.data.id);
        }
    });
});
